home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
8614
/
8614.xpi
/
modules
/
utils
/
Prefs.jsm
< prev
next >
Wrap
Text File
|
2010-02-10
|
10KB
|
396 lines
// DO NOT import this into the global namespace, but instead
// import it into your own namespace wrapper
var EXPORTED_SYMBOLS = ["Prefs"];
Components.utils.import("resource://glydo/utils/prototype_xul_1_6_0_3_modified.jsm");
Components.utils.import("resource://glydo/utils/Utils.jsm");
var Prefs = ({
init: function() {
this.prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
this.prefBranch = this.prefService.getBranch("glydo.");
this.prefBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.prefBranch.addObserver("",this,false);
this.browserBranch = this.prefService.getBranch("browser.");
this.browserBranch.QueryInterface(Components.interfaces.nsIPrefBranch2);
this.listenersByKey = {};
},
write: function(key, value) {
var type = 'char';
var branch = this.prefBranch;
if (arguments[2]) {
type = arguments[2];
}
if (arguments[3]) {
branch = arguments[3];
}
try {
switch (type.toLowerCase()) {
case 'char':
branch.setCharPref(key, value);
break;
case 'bool':
branch.setBoolPref(key, value);
break;
case 'int':
branch.setIntPref(key, value);
break;
default:
throw "Unsupported preference type";
}
}
catch (ex) {
Utils.dump("\nFailed writing preference for '" + key + "': '" + value + "': " + ex + "\n");
}
try {
this.prefService.savePrefFile(null);
}
catch (ex) {
Utils.dump("\nFailed saving preferences: " + ex + "\n");
}
},
read: function(key, defValue) {
var type = 'char';
var branch = this.prefBranch;
if (arguments[2]) {
type = arguments[2];
}
if (arguments[3]) {
branch = arguments[3];
}
var value;
try {
switch (type.toLowerCase()) {
case 'char':
value = branch.getCharPref(key);
break;
case 'bool':
value = branch.getBoolPref(key);
break;
case 'int':
value = branch.getIntPref(key);
break;
default:
throw "Unsupported preference type";
}
}
catch (ex) {
if (ex.name != "NS_ERROR_UNEXPECTED") {
}
value = defValue;
}
return value;
},
readAny: function(key) {
var branch = this.prefBranch;
if (arguments[1]) {
branch = arguments[1];
}
var t = branch.getPrefType(key);
switch (t) {
case branch.PREF_STRING:
return branch.getCharPref(key);
case branch.PREF_BOOL:
return branch.getBoolPref(key);
case branch.PREF_INT:
return branch.getIntPref(key);
default:
return null;
}
},
subscribe: function(key,callback) {
var listeners = this.listenersByKey[key];
if (!listeners) {
listeners = [];
}
listeners.push(callback);
this.listenersByKey[key] = listeners;
},
unsubscribe: function(key,callback) {
var listeners = this.listenersByKey[key];
this.listenersByKey[key] = Prototype.A.without(listeners,callback);
},
observe: function(aSubject, aTopic, aData) {
if (aTopic != "nsPref:changed") {
return;
}
var listeners = this.listenersByKey[aData] || [];
// Add global listeners
listeners = listeners.concat(this.listenersByKey[""] || []);
if (listeners && listeners.length > 0) {
var v = this.readAny(aData);
listeners.forEach(function(listener) {
try {
listener(aData,v);
} catch (ex) {
if (Components) {
Components.utils.reportError(ex);
} else {
throw ex;
}
}
});
}
},
get recommendations_open_mode () {
return this.read('behavior.recommendations_open_mode','new-tab','char');
},
set recommendations_open_mode (value) {
this.write('behavior.recommendations_open_mode',value,'char');
},
get server_base_url() {
var base = this.read('connection.server_url.base',null,'char');
if (!Prototype.S.endsWith(base,"/")) {
base += '/';
}
return base;
},
set server_base_url(value) {
this.write('connection.server_url.base',value,'char');
},
server_part_url: function(rel ) {
var base = this.server_base_url;
return Utils.newURI(rel,base).spec;
},
get server_url () {
return this.server_part_url(
'RecommenderServlet'
);
},
get reporting_server_url () {
return this.server_part_url(
'PeriodicalReportServlet'
);
},
get resources_repository_url() {
return this.read("connection.resources_repository.url",null,'char');
},
get resources_repository_sync_interval_millis() {
return this.read("connection.resources_repository.sync.interval.minutes",360,'int')*60*1000;
},
get offline_source_dir() {
return this.read('offline.source_dir',null,'char');
},
set offline_source_dir(value) {
this.write('offline.source_dir',value,'char');
},
get offline_log_dir() {
return this.read('offline.log_dir',null,'char');
},
set offline_log_dir(value) {
this.write('offline.log_dir',value,'char');
},
get offline_log_with_offline_source() {
return this.read('offline.log_with_offline_source',false,'bool');
},
set offline_log_with_offline_source(value) {
this.write('offline.log_with_offline_source',value,'bool');
},
get history_max_length() {
return this.read('behavior.history.max_length',2,'int');
},
set history_max_length(value) {
this.write('behavior.history.max_length',value,'int');
},
get history_max_valid() {
return this.read('behavior.history.max_valid',2,'int');
},
set history_max_valid(value) {
this.write('behavior.history.max_valid',value,'int');
},
get report_send_interval_mins() {
return this.read('reporting.send_interval_mins',15,'int');
},
set report_send_interval_mins(value) {
this.write('reporting.send_interval_mins',value,'int');
},
get server_trace() {
return this.read('connection.server_trace',false,'bool');
},
set server_trace(value) {
this.write('connection.server_trace',value,'bool');
},
get db_recs_acks_max_age_millis() {
return this.read("db.recs_acks.max_age_days",14,'int')*24*60*60*1000;
},
set db_recs_acks_max_age_millis(value) {
this.write('db.recs_acks.max_age_days',Math.ceil(value/(24*60*60*1000)),'int');
},
get ticker_change_interval_millis() {
return this.read("behavior.ticker.change_interval_secs",10,'int')*1000;
},
set ticker_change_interval_millis(value) {
this.write('behavior.ticker.change_interval_secs',Math.round(value/1000),'int');
},
on_ticker_change_interval_millis_changed: function(callback) {
this.subscribe("behavior.ticker.change_interval_secs",callback);
},
get ticker_show() {
return this.ticker_change_interval_millis > 0;
},
get ticker_ads_period() {
return this.read("behavior.ticker.ads.period",4,'int');
},
get teaser_min_interval_millis() {
return this.read("behavior.teaser.min_interval_secs",20*60,'int')*1000;
},
set teaser_min_interval_millis(value) {
this.write('behavior.teaser.min_interval_secs',Math.round(value/1000),'int');
},
get teaser_min_open_time_for_ack_millis() {
return this.read("behavior.teaser.min_open_time_for_ack_secs",3,'int')*1000;
},
set teaser_min_open_time_for_ack_millis(value) {
this.write('behavior.teaser.min_open_time_for_ack_secs',Math.round(value/1000),'int');
},
get teaser_show() {
return this.read("behavior.teaser.show",true,'bool');
},
set teaser_show(value) {
this.write('behavior.teaser.show',value,'bool');
},
get teaser_auto_hide_interval_millis() {
return this.read("behavior.teaser.auto_hide_interval_secs",10,'int')*1000;
},
set teaser_auto_hide_interval_millis(value) {
this.write('behavior.teaser.auto_hide_interval_secs',Math.round(value/1000),'int');
},
get cache_max_entries() {
return this.read("performance.cache.max_entries",100,'int');
},
set cache_max_entries(value) {
this.write('performance.cache.max_entries',value,'int');
},
get cache_max_age_millis() {
return this.read("performance.cache.max_age_secs",1200,'int')*1000;
},
set cache_max_age_millis(value) {
this.write('performance.cache.max_age_secs',Math.round(value/1000),'int');
},
get max_recs_from_server_to_process() {
return this.read("performance.server.max_recs_to_process",100,'int');
},
set max_recs_from_server_to_process(value) {
this.write('performance.server.max_recs_to_process',value,'int');
},
get total_task_max() {
return this.read("performance.textex.total_task_max",12000,'int');
},
set total_task_max(value) {
this.write('performance.textex.total_task_max',value,'int');
},
get task_phase_max() {
return this.read("performance.textex.task_phase_max",50,'int');
},
set task_phase_max(value) {
this.write('performance.textex.task_phase_max',value,'int');
},
get task_break() {
return this.read("performance.textex.task_break",40,'int');
},
set task_break(value) {
this.write('performance.textex.task_break',value,'int');
},
get uninstall_survey_url() {
return this.read("behavior.uninstall.survey_url",null,'char');
},
set last_installed_version(value) {
this.write('general.install.last_version',value,'char');
},
get last_installed_version() {
return this.read("general.install.last_version",null,'char');
},
set default_search_engine(value) {
this.write('search.selectedEngine',value,'char',this.browserBranch);
},
get default_search_engine() {
return this.read("search.selectedEngine",null,'char',this.browserBranch);
},
set publishers(values) {
this.write('behavior.publishers',Prototype.O.toJSON(Prototype.A.uniq(values,false)),'char');
},
get publishers() {
return Prototype.S.decodeJSON(this.read("behavior.publishers",'[]','char'));
},
addPublishers: function(values) {
this.publishers = Prototype.A.uniq(this.publishers.concat(values),false);
},
set engines(values) {
this.write('behavior.engines',Prototype.O.toJSON(Prototype.A.uniq(values,false)),'char');
},
get engines() {
return Prototype.S.decodeJSON(this.read("behavior.engines",'[]','char'));
},
addEngines: function(values) {
this.engines = Prototype.A.uniq(this.engines.concat(values),false);
},
});
Prefs.init();